package com.lex.samismyfather;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.lex.adapter.HistoryRecordAdapter;
import com.lex.entity.ContactEntity;
import com.lex.entity.RecordEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/6/7.
 */
public class HistoryFragment extends BaseFragment {
    private static HistoryFragment self;

    public HistoryFragment(){
        super(R.layout.activity_history);
    }

    public static synchronized HistoryFragment getInstance(){
        if (self == null) self = new HistoryFragment();
        return self;
    }

    private ListView hisList;

    @Override
    protected void findView() {
        hisList = (ListView) findViewById(R.id.list_his);
    }

    @Override
    protected void initView() {
        HistoryRecordAdapter historyRecordAdapter = new HistoryRecordAdapter(getActivity(),getRecordData());
        hisList.setAdapter(historyRecordAdapter);
        hisList.setOnItemClickListener(new AdapterView.OnItemClickListener(){
            public void onItemClick(AdapterView<?> parent, View view, int position, long id){
                Toast.makeText(getActivity(),"第"+position+"条被点击",Toast.LENGTH_SHORT).show();
            }
        });
    }

    private List<RecordEntity>getRecordData(){
        List<RecordEntity>recordEntityList = new ArrayList<>();
        ContactEntity contactEntity = new ContactEntity("赵钱孙李","18888888888");
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.TEXT,"孙行者",RecordEntity.RECORD_FROM.MAKE));
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.CONTACT,contactEntity,RecordEntity.RECORD_FROM.SCAN));
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.TEXT,"行者孙",RecordEntity.RECORD_FROM.MAKE));
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.URL,"http://www.baidu.com",RecordEntity.RECORD_FROM.SCAN));
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.CONTACT,contactEntity,RecordEntity.RECORD_FROM.MAKE));
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.TEXT,"者行孙",RecordEntity.RECORD_FROM.MAKE));
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.URL,"http//www.qq.com",RecordEntity.RECORD_FROM.SCAN));
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.TEXT,"者行孙",RecordEntity.RECORD_FROM.MAKE));
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.TEXT,"者行孙",RecordEntity.RECORD_FROM.MAKE));
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.TEXT,"者行孙",RecordEntity.RECORD_FROM.MAKE));
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.TEXT,"者行孙",RecordEntity.RECORD_FROM.MAKE));
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.TEXT,"者行孙",RecordEntity.RECORD_FROM.MAKE));
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.TEXT,"者行孙",RecordEntity.RECORD_FROM.MAKE));
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.TEXT,"者行孙",RecordEntity.RECORD_FROM.MAKE));
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.TEXT,"者行孙",RecordEntity.RECORD_FROM.MAKE));
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.TEXT,"者行孙",RecordEntity.RECORD_FROM.MAKE));
        return recordEntityList;
    }

}
